package 剑指offer;

/**
 * Created by yang on 2016/8/24.
 */
public class PowerOfTwoNumber {
    public double Power(double base, int exponent) {

        if (exponent == 0) {
            return 1;
        }

        if(exponent == 1) {
            return base;
        }

        boolean flagNegtive = false;
        if(exponent < 0) {
            flagNegtive = true;
            exponent = Math.abs(exponent);
        }

        double tmp = base;
        // not 1 or 0
        for (int i = 1;i < exponent; i++) {

            base = base * tmp;
        }

        if(flagNegtive) {
            return 1/base;
        }
        return base;
    }
}
